package com.cmcc.fj12580.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;

import com.cmcc.fj12580.R;
import com.cmcc.fj12580.utils.WBUserBean;

public class WBShareAdapter extends BaseAdapter {

	private Context context;
	private List<WBUserBean> list;

	public WBShareAdapter(Context context, List<WBUserBean> list) {
		this.context = context;
		this.list = list;

	}

	public int getCount() {
		return list.size();
	}

	public Object getItem(int position) {
		return list.get(position);
	}

	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		WBUserBean user = list.get(position);
		ViewHolder viewholder = null;
		if (convertView == null) {
			LayoutInflater layoutinflator = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView = layoutinflator.inflate(R.layout.wbshare_item, null);
			viewholder = new ViewHolder();
			viewholder.wbshare_cb = (CheckBox) convertView.findViewById(R.id.wbshare_cb);
			viewholder.share_iv=(ImageView) convertView.findViewById(R.id.share_iv);
			viewholder.wbshare_name = (TextView) convertView.findViewById(R.id.wbshare_name);
			viewholder.wbshare_login = (TextView) convertView.findViewById(R.id.wbshare_login);
			convertView.setTag(viewholder);
		} else {
			viewholder = (ViewHolder) convertView.getTag();
		}
		viewholder.share_iv.setBackgroundResource(user.getImage());
		viewholder.wbshare_cb.setChecked(user.isLogin());
		viewholder.wbshare_login.setText(user.getLoginD());
		viewholder.wbshare_name.setText(user.getName());
		return convertView;
	}

	class ViewHolder {
		CheckBox wbshare_cb;
		ImageView share_iv;
		TextView wbshare_name;
		TextView wbshare_login;
	}

}
